package com.cn.news.service.impl;

import com.cn.common.pojo.NewsModel;
import com.cn.common.pojo.ResultModel;
import com.cn.news.mapper.NewsDao;
import com.cn.news.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NewsServiceImpl implements NewsService {
    @Autowired
    NewsDao newsDao;

    @Override
    public ResultModel newsForNews() {
        return ResultModel.Data(newsDao.newsForNews());
    }

    @Override
    public List<NewsModel> newsByType(int type) {
        return newsDao.newsByType(type);
    }

    @Override
    public ResultModel news() {
        return ResultModel.Data(newsDao.news());
    }

    @Override
    public ResultModel delete(int id) {
        int delete = newsDao.delete(id);
        return ResultModel.getResultModelByCount(delete);
    }

    @Override
    public ResultModel update(NewsModel newsModel) {
        int update = newsDao.update(newsModel);
        return ResultModel.getResultModelByCount(update);
    }

    @Override
    public ResultModel insert(NewsModel newsModel) {
        int insert = newsDao.insert(newsModel);
        return ResultModel.getResultModelByCount(insert);
    }

    @Override
    public ResultModel enable(int id) {
        int enable = newsDao.enable(id);
        return ResultModel.getResultModelByCount(enable);
    }

    @Override
    public ResultModel findById(int id) {

        return ResultModel.success(newsDao.findById(id));
    }

    @Override
    public ResultModel limit(NewsModel newsModel) {
        int count = newsDao.count(newsModel);
        return ResultModel.success(newsDao.limit(newsModel),count);

    }

    @Override
    public ResultModel newsForId(int id) {
        List<NewsModel> newsModels = newsDao.newsForId(id);
        return ResultModel.getResultModel("",0,1,newsModels);
    }
}
